<template>
  <div class="container container-scroll">
    <van-tabs
      v-if="list.length"
      :active="currentTab"
      swipeable
      sticky
      animated
      title-active-color="#ee732f"
      :ellipsis="false"
      color="#ee732f"
      @change="onChangeTab"
    >
      <van-tab
        v-for="(item,index) in list"
        :key="index"
        :title="item.title"
        :name="item.id"
      >
        <zhixu
          v-if="item.componentName === 'zhixu'"
          :params="item.mplink"
        />
        <sign
          v-else-if="item.componentName === 'sign'"
          :params="item.mplink"
          :gis="gis"
          @signin="onSignin"
        />
        <jifen
          v-else-if="item.componentName === 'jifen'"
          :params="item.mplink"
        />
        <van-empty
          v-else
          description="暂无内容"
        />
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import Zhixu from '@/components/room/zhixu'
import Sign from '@/components/room/sign'
import Jifen from '@/components/room/jifen'
import { getPageTabsApi, getSigninViewApi, postSigninApi } from '@/api'
export default {
  components: {
    Zhixu,
    Sign,
    Jifen
  },
  data () {
    return {
      active: 1,
      list: [],
      gis: null,
      currentTab: ''
    }
  },
  onShow () {
    this.onLoadData()
  },
  watch: {
    currentTab (value) {
      this.onLoadTabList(value)
    }
  },
  methods: {
    onChangeTab (e) {
      this.currentTab = e.mp.detail.name
    },
    onLoadData () {
      getPageTabsApi('room').then(res => {
        this.list = res
      })
    },
    onLoadSigninData () {
      getSigninViewApi().then(res => {
        this.gis = res
      })
      // wx.onLocationChange()
    },
    onSignin (data) {
      postSigninApi(data).then(res => {
        this.gis = res
      })
    },
    onLoadTabList (value) {
      if (this.list && this.list.length > 0) {
        for (let i = this.list.length; i--;) {
          var item = this.list[i]
          if (item.id === value && item.componentName === 'sign') {
            this.onLoadSigninData()
            break
          }
        }
      }
    }
  }
}
</script>

<style lang="less">
.tab-image {
  width: 100%;
}
.van-tabs__content {
  min-height: calc(100vh - 52px);
}
</style>
